home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9093 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news-m01.ny.us.ibm.net!usenet
  2. From: bbogard@ibm.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What does this "const" mean?
  5. Date: 28 Feb 1996 16:39:52 GMT
  6. Message-ID: <4h20go$154o@news-s01.ny.us.ibm.net>
  7. References: <4h0j7u$htp@crcnis3.unl.edu>
  8. Reply-To: bbogard@ibm.net
  9. NNTP-Posting-Host: slip37-223-98.ibm.net
  10. X-Newsreader: IBM NewsReader/2 v1.2.5
  11.  
  12. >     I have some problems regarding this program segment:
  13. >
  14. >         class intset {
  15. >             // ...
  16. >             void start(int& i) const   { i = 0; }
  17. >             int ok(int& i) const       { return i<cursize; }
  18. >             int next(int& i) const     { return x[i++]; }
  19. >         };
  20. >
  21. >     What does "const" mean in this program segment?  What role does
  22. >it play?  In what kind of situation will we use "const" like this?
  23.  
  24. the const after these functions, forces the implementation of these functions to not modify
  25. the object that contains these functions.  In other words, any function with a const after its
  26. declaration can only look at data members in the object and not modify them.  This also means
  27. that it can only call const functions in the same object and other objects.
  28.